﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKSparseDistance.Properties;
using YJKRoomInspection.ProgramArchitecture;
using YJKRoomInspection.Utiltiy;
using YArchitech.Controls;

namespace YJKSparseDistance.ControlLayer
{
	public class FrontRoomArch
	{
		public static UIApplication UseUIApp
		{
			get
			{
				return FrontRoomArch.m_useUiApp;
			}
			private set
			{
				FrontRoomArch.m_useUiApp = value;
			}
		}

		public FrontRoomArch(UIApplication inputUiApp, IFlowYJKRoomInspection flowChecker, ExternalCommandData inputCommand, List<Level> inputLevel, IWin32Window inputRevitHandle)
		{
			FrontRoomArch.UseUIApp = null;
			FrontRoomArch.UseUIApp = inputUiApp;
			this.m_UseFlowChecker = flowChecker;
			this.m_useCommand = inputCommand;
			this.m_selectLevel = inputLevel;
			this.m_useRevitHandle = inputRevitHandle;
		}

		public void IfNeedYJKRoomInspection(Autodesk.Revit.DB.Document useDoc, List<Level> inputLevels)
		{
            IEnumerable<IGrouping<int, Element>> enumerable = from n in YJKRoomInspection.Utiltiy.Utility.FilterElementFormDoc(FrontRoomArch.UseUIApp.ActiveUIDocument, inputLevels)
			group n by n.LevelId.IntegerValue;
			List<int> list = new List<int>();
			foreach (IGrouping<int, Element> grouping in enumerable)
			{
				list.Add(grouping.Key);
			}
			List<Level> list2 = new List<Level>();
			foreach (Level level in inputLevels)
			{
				if (!list.Contains(level.Id.IntegerValue))
				{
					list2.Add(level);
				}
			}
			if (list2.Count > 0)
			{
				StringBuilder stringBuilder = new StringBuilder();
				for (int i = 0; i < list2.Count; i++)
				{
					if (i < list2.Count - 1)
					{
						stringBuilder.Append(list2[i].Name + ",");
					}
					else
					{
						stringBuilder.Append(list2[i].Name);
					}
				}
				if (YJKMessageBox.Show(stringBuilder.ToString() + Resources.Str_NoneFrontRoom, MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					PublicYJKRoomInspection publicYJKRoomInspection = new PublicYJKRoomInspection(this.m_useCommand, this.m_selectLevel, this.m_useRevitHandle);
					publicYJKRoomInspection.DoCheck();
					if (publicYJKRoomInspection.IfManualAbosrt)
					{
						return;
					}
				}
			}
			if (this.m_UseFlowChecker != null)
			{
				this.m_UseFlowChecker.CheckMethod();
			}
		}

		private static UIApplication m_useUiApp;

		private IFlowYJKRoomInspection m_UseFlowChecker;

		private ExternalCommandData m_useCommand;

		private List<Level> m_selectLevel;

		private IWin32Window m_useRevitHandle;
	}
}
